#include <stdio.h>
#include <stdlib.h>

#ifdef COMPILE_DEFINITIONS_LIST

#include "list.h"

int main() {
    list *handler = NULL;
    int ret = 0;
    int i = 0;
    int *temp = NULL;
    int8_t size = 0;

    ret = list_init(&handler);
    if(ret != LIST_OK) {
        printf("list initialization error, code: 0x%04x\n", ret);
        goto exit;
    }

    for(i = 0; i < 10; i++) {
        temp = (int *)malloc(sizeof(int));
        *temp = i + 1;
        ret = list_add(handler, temp);
        if(ret != LIST_OK) {
            printf("list add error, code: 0x%04x\n", ret);
            goto exit;
        }
    }

    temp = NULL;

    ret = list_size(handler, (int64_t *)&size);
    if(ret != LIST_OK) {
        printf("list get isze error, code: 0x%04x\n", ret);
        goto exit;
    }
    printf("list size is %d\n", size);

    for(i = 0; i < 10; i++) {
        ret = list_get_at(handler, i + 1, (void **)&temp);
        if(ret != LIST_OK) {
            printf("list get error, code: 0x%04x\n", ret);
            goto exit;
        }
        printf("%d\n", *temp);
    }

    printf("start list free at\n\n\n");

    ret = list_free_at(handler, 10);
    if(ret != LIST_OK) {
        printf("list free at error, index is %d, error code is 0x%04x\n", 4, ret);
        goto exit;
    }
    for(i = 0; i < 9; i++) {
        ret = list_get_at(handler, i + 1, (void **)&temp);
        if(ret != LIST_OK) {
            printf("list get error, code: 0x%04x\n", ret);
            goto exit;
        }
        printf("%d\n", *temp);
    }

    temp = (int *)malloc(sizeof(int));
    *temp = 4;

    printf("start list add at\n\n\n");
    ret = list_add_at(handler, 4, temp);
    if(ret != LIST_OK) {
        printf("list add error, code: 0x%04x\n", ret);
        goto exit;
    }
    for(i = 0; i < 10; i++) {
        ret = list_get_at(handler, i + 1, (void **)&temp);
        if(ret != LIST_OK) {
            printf("list get error, code: 0x%04x\n", ret);
            goto exit;
        }
        printf("%d\n", *temp);
    }

exit:
    list_free_all(&handler);

    return 0;
}
#else

int main() {
    printf("please use defination:\'COMPILE_DEFINITIONS_LIST\' to rebuild this project\n");
    return 0;
}

#endif